import request from "../utils/request";

// 分类提交
export const coursePost = (obj) => {
  return request.post("classes/courseData", obj);
};

// 分类获取
export const courseGet = (bool) => {
  const where = bool
    ? {
        parent: "0-0",
      }
    : {};
  return request.get("classes/courseData", {
    params: {
      where,
    },
  });
};

// 分类删除
export const courseDel = (id) => {
  return request.delete(`classes/courseData/${id}`);
};

//图文提交
export const articlePost = (obj) => {
  return request.post("classes/articleData", obj);
};

// 图文获取
export const articleGet = (article) => {
  const { name, vip } = article;
  const where = {};
  if (name) {
    where.name = { $regex: name, $options: "i" };
  }
  if (typeof vip != "boolean" && vip != undefined) {
    console.log(JSON.parse(vip));
    where.vip = JSON.parse(vip);
  }
  let query = JSON.stringify(where);
  return request.get(`classes/articleData?where=${query}`);
};
